package com.efesco.crm.crm;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * materialQueryViewModel
 */
public class materialQueryViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
	  DBStatement dbs=new DBStatement();
	  Dataset dsservice =getDataset("datasetCondition");
   Dataset dsemh =getDataset("datasetHabitation");
   Dataset dsgregress =getDataset("datasetRegress");
   Dataset dsseparation =getDataset("datasetSeparation");
   Dataset dsother =getDataset("datasetResultOther");
   dsemh.moveFirst();
   dsgregress.moveFirst();
   dsseparation.moveFirst();
   dsother.moveFirst();
   while(!dsemh.isLast()){
	   if(dsemh.getBoolean("select")){
		   dbs.setSql("delete from s_em_card_habitation  where EM_CARD_HABITATION_ID="+dsemh.getValue("EM_CARD_HABITATION_ID") );
		   dbs.execute(); 
		   dbs.setSql("delete from s_employee_material em where em.employee_id="+dsemh.getValue("EMPLOYEE_ID")+" and em.service_material_id in(select service_material_id from s_service_material sm where sm.in_char_service_id= "+dsservice.getValue("service_id")+")" );
		   dbs.execute();
	   }
	   dsemh.moveNext();
   }
   while(!dsgregress.isLast()){
	   if(dsgregress.getBoolean("select")){
		   dbs.setSql("delete from s_em_card_regress  where EM_CARD_REGRESS_ID="+dsgregress.getValue("EM_CARD_REGRESS_ID") );
		   dbs.execute(); 
		   dbs.setSql("delete from s_employee_material em where em.employee_id="+dsgregress.getValue("EMPLOYEE_ID")+" and em.service_material_id in(select service_material_id from s_service_material sm where sm.in_char_service_id= "+dsservice.getValue("service_id")+")" );
		   dbs.execute();
		
	   }
	   dsgregress.moveNext();
   }
   while(!dsseparation.isLast()){
	   if(dsseparation.getBoolean("select")){
		   dbs.setSql("delete from s_em_card_separation  where EM_CARD_SEPARATION_ID="+dsseparation.getValue("EM_CARD_SEPARATION_ID") );
		   dbs.execute(); 
		   dbs.setSql("delete from s_employee_material em where em.employee_id="+dsseparation.getValue("EMPLOYEE_ID")+" and em.service_material_id in(select service_material_id from s_service_material sm where sm.in_char_service_id= "+dsservice.getValue("service_id")+")" );
		   dbs.execute();
	   }
	   dsseparation.moveNext();
   }
   while(!dsother.isLast()){
	   if(dsother.getBoolean("select")){
		   dbs.setSql("delete from s_em_card_regress  where EM_CARD_REGRESS_ID="+dsother.getValue("EM_CARD_REGRESS_ID") );
		   dbs.execute(); 
		   dbs.setSql("delete from s_employee_material em where em.employee_id="+dsother.getValue("EMPLOYEE_ID")+" and em.service_material_id in(select service_material_id from s_service_material sm where sm.in_char_service_id= "+dsservice.getValue("service_id")+")" );
		   dbs.execute();
	   }
	   dsother.moveNext();
   }
   
  dbs.close();
  }

}
